from typing import List


class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        # 维护一个窗口，窗口中0出现的次数为<=1
        left=0
        zero_cnt=0
        max_len=0
        for right in range(len(nums)):
            if nums[right]==0:
                zero_cnt+=1
            while zero_cnt>1:
                # 移除左窗口
                if nums[left]==0:
                    zero_cnt-=1
                left+=1
            # 当前窗口长度为（right-left+1）,删除一个0
            max_len=max(max_len,right-left)
        return max_len